<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ReportLabel extends Model
{
    protected $table = "c_report_labels";

    /****
     * @param $data
     * @return bool
     * 添加备忘录
     */
    public function doSetting($data)
    {
        if (isset($data['id']) && !empty($data['id'])) {
            $redata = $this->getInfo($data['id']);
//            $redata->case_id = $data['case_id'];
            $redata->label = $data['label'];
            $redata->user_id = $data['user_id'];
            $res = $redata->save();
        } else {
            //添加
//            $this->case_id = $data['case_id'];
            $this->label = $data['label'];
            $this->user_id = $data['user_id'];
            $res = $this->save();
        }
        return $res;
    }

    /***
     * @param $data
     * @return mixed
     * 获取备忘录信息
     */
    public function getInfo($id)
    {
        return $this->where([['id', '=', $id]])->first();
    }

    /****
     * @param $data
     * 获取病历标签
     */
    public function getReportLabelList($param)
    {
        $where = [];
        if (isset($param['start']) && !empty($param['start'])) {  //开始时间
            $where[] = ['ins_times', '>=', $param['start']];
        }
        if (isset($param['end']) && !empty($param['end'])) {  //开始时间
            $where[] = ['ins_times', '<=', $param['end']];
        }
        if (isset($param['title']) && !empty($param['title'])) {  //标题
            $where[] = ['tags', 'like', '%' . $param['title'] . '%'];
        }
        $list = $this->where([['user_id', '=', $param['user_id']]])->where($where)->orderByDesc("id")->get();
        if (!empty($list)) {
            $list = $list->toArray();
            return $list;
        }
        return [];
    }

    public function delReportLabel($data)
    {
        return $this::destroy($data['id']);
    }

}
